<template>
	<view class="content">
		<scroll-view :scroll-y="true" @scrolltolower="getDisplay" class="list">
			<view class="item" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
				<view class="left">
					<view class="choose">
						<image v-if="info.address.id==item.id" src="/static/choose.png"></image>
						<image v-else src="/static/no-choose.png"></image>
					</view>
					<view class="address">
						<view class="u-box">
							<text class="name">{{item.realname}}</text>
							<text class="mobile">{{item.mobile}}</text>
							<text v-if="item.isdefault==1" class="tag">默认地址</text>
						</view>
						<view class="address-box">
							
							<text class="address">{{item.province}} {{item.city}} {{item.area}} {{item.address}}</text>
							
						</view>
					</view>
				</view>
				<view class="right">
					<image src="/static/edit.png" mode="widthFix" @click.stop="addAddress('edit', item)"></image>
				</view>
			</view>
		</scroll-view>
		<view class="btn">
			<view class="btn_color_new"  @click.stop="addAddress('add')">
				+ 新增地址
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				source: 0,
				addressList: [],
				page: 0,
				cartids: '',
				type: '',
				id: '',
				optionid: '',
				total: '',
				zhiboid: '',
				options: '',
				isVip: 0,
				isGroupBuy: 0,
			}
		},
		props: {
			info:{
				type: Object,
				default: {}
			}
		},
		created() {
			this.page=0;
			this.addressList=[];
		},
		methods: {
			clearList(){
				this.page = 0;
				this.addressList=[];
			},
			getDisplay(){
				this.page++;
				this.$axios('address/display', "POST", 'shop', {
					page: this.page
				}).then(res => {
					if (res.data.code == 200) {
						this.addressList = [...this.addressList,...res.data.data.list]
					}
				})
			},
			//选择地址
			checkAddress(item) {
				uni.setStorageSync('addre', JSON.stringify(item));
				this.$emit('closepop');
				this.$emit('getInfo');
			},
			addAddress(type,item) {
				if(type=='add'){
					this.$navTo('/pages/address/addressManage');
				}else{
					uni.navigateTo({
						url: `/pages/address/addressManage?data=${JSON.stringify(item)}&type=${type}`
					})
				}
			},
		}
	}
</script>

<style lang='scss'>
	page {
		padding-bottom: 120upx;
		background: #FBF8FE;
	}

	.bg {
		width: 100%;
		background: linear-gradient(180deg, #4B05A7 0%, #A34DE8 52%, #FBF8FE 100%);
		height: 400rpx;
		position: fixed;
		z-index: 1;
	}

	.content {
		/* position: relative; */
	}

	.list {
		position: relative;
		z-index: 2;
		padding: 20rpx 0 56rpx;
		height: 800rpx;
	}

	.item {
		background: #fff;
		border-radius: 12rpx;
		padding: 20rpx;
		margin-bottom: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.left{
			display: flex;
			align-items: center;
			width: 90%;
			.address{
				width: 100%;
			}
			.tag {
				font-size: 20rpx;
				color: #8615E1;
				margin-right: 14rpx;
				border: 1rpx solid #9A1FE8;
				border-radius: 8rpx;
				height: 28rpx;
				line-height: 28rpx;
				padding: 0 10rpx;
				margin-top: 2rpx;
				font-weight: normal;
				margin-left: 15rpx;
				white-space: nowrap;
			}
			
			image{
				
				margin-right: 30rpx;
			}
		}
		image{
			width: 40rpx;
			height: 40rpx;
		}
	}

	.address-box {
		display: flex;
		align-items: flex-start;
		/* border-bottom: 1rpx solid #DEDEDE; */
		padding: 20rpx 0;

		
		.address {
			font-size: 24rpx;
			color: #333333;
			flex: 1;
		}

		image {
			width: 40rpx;
		}
	}

	.edit {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-top: 20rpx;
		color: #999999;
		font-size: 24rpx;

		text {
			padding-left: 6rpx;
		}
	}

	.u-box {
		font-size: 28rpx;
		color: #333333;
		font-weight: 600;

		.name {
			margin-right: 14rpx;
		}
	}

	.icon-bianji {
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: $font-color-light;
		padding-left: 30upx;
	}

	.btn {
		position: fixed;
		left: 0;
		right: 0;
		background-color: #fff;
		bottom: 0;
		padding: 30rpx 20rpx;
		box-shadow: 0px 8rpx 20rpx 0px rgba(0, 0, 0, 0.3);
		border-top-left-radius: 16rpx;
		border-top-right-radius: 16rpx;
		.btn_color_new{
			background: linear-gradient(94deg, #FF38E5 0%, #8813E2 61%);
			width: 100%;
			line-height: 84rpx;
			text-align: center;
			border-radius: 24rpx;
			color: #FFFFFF;
			font-weight: bold;
		}
	}
</style>